# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Valery Kartel <valery.kartel@gmail.com>
pkgname=capstone
pkgver=5.0.1
pkgrel=4
pkgdesc="The Ultimate Disassembler"
url="https://www.capstone-engine.org"
arch="all"
license="BSD-3-Clause-Clear"
depends_dev="$pkgname"
makedepends="bash py3-setuptools cython python3-dev"
subpackages="$pkgname-static $pkgname-dev py3-$pkgname-pyc py3-${pkgname}:_py3 cstool"
source="$pkgname-$pkgver.tar.gz::https://github.com/aquynh/capstone/archive/$pkgver.tar.gz
	0001-Revert-Update-constants-from-ARM-auto-sync-patch-224.patch
	py-path-fix.patch
	"

build() {
	export CFLAGS="$CFLAGS -O2 -flto=auto -ffat-lto-objects"
	make
	cd bindings/python
	python3 setup_cython.py build
}

check() {
	make check
}

package() {
	make PREFIX=/usr DESTDIR="$pkgdir" install

	cd bindings/python
	python3 setup_cython.py install --skip-build --root="$pkgdir"

	rm -rf "$pkgdir"/usr/lib/python3*/site-packages/capstone/lib
	rm -rf "$pkgdir"/usr/lib/python3*/site-packages/capstone/include
}

_py3() {
	pkgdesc="$pkgdesc (for python3)"
	depends="py3-setuptools"

	amove usr/lib/python*
}

cstool() {
	pkgdesc="cstool for capstone disassembler"

	amove usr/bin/cstool
}

sha512sums="
350aba77ce2d96b5c25764913591ba80e4497177ae0a8b2c820c6755ee8310848fbfc54e7ccac27fafc2dbc6778118ad92c53d1b5cb601d4fa146dec7d7e11e5  capstone-5.0.1.tar.gz
86254e4f42107ceb29c65b227acdf2b4375ba8b7e076ee53fac649feddb478f08c7b23d61e63d0c96068e6d993116b96ec7c714dbe0247aa3458b63d0a2d3f94  0001-Revert-Update-constants-from-ARM-auto-sync-patch-224.patch
e9a2d7cb391285890872123fb3e5ae8f8cde6e4f858c31f5c815c110f6c6d5ec86cef4920b277d5630745a34a268e52b402855429b072f0b5a722d6a610366a8  py-path-fix.patch
"
